# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pcre2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=10.33
pkgrel=1
pkgdesc="A library that implements Perl 5-style regular expressions (mingw-w64)"
arch=('any')
url="https://pcre.org/"
license=("BSD")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-bzip2"
         #"${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-wineditline"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=(https://ftp.pcre.org/pub/pcre/${_realname}-${pkgver}.tar.bz2{,.sig}
        0001-RunTest-skip-test-that-must-fail-on-Windows.patch
        0002-RunTest-skip-a-couple-more-tests-on-Windows.patch
        0003-RunGrepTest-compare-without-paying-attention-to-line.patch
        0004-RunGrepTest-skip-test-with-absolute-Unix-path.patch
        0005-RunGrepTest-skip-script-callout-test.patch
        0006-Fix-INTERACTIVE-fd-on-Windows.patch)
sha256sums=('35514dff0ccdf02b55bd2e9fa586a1b9d01f62332c3356e379eabb75f789d8aa'
            'SKIP'
            'a20c4c3a340d4e8b3fb0a22197796777e6a9f21d46b6f98164750931543a2d9f'
            'f73ccc5ba01faa0772f802da354dbef89ea4306344ee36fb1a9e92d616b1fd48'
            '3689af7b69804295140062a2e70b5b61e7e949abacd39ddbfa8d933447f16979'
            '3f7b6a2de5fd5478b44aeadb98d217988fc1576418430ecb746ddf16582755d5'
            'fcaeffd0ab12691c7d0e793dc6cb39116cbbea41050b1b7ff1a9f7a80b272d62'
            '2482fa16c728c247505e59d6ce7798fdd9387699b0dce7146627177b687246ea')
validpgpkeys=('45F68D54BBE23FB3039B46E59766E084FB0F43D8')

prepare () {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 <"${srcdir}"/0001-RunTest-skip-test-that-must-fail-on-Windows.patch
  patch -p1 <"${srcdir}"/0002-RunTest-skip-a-couple-more-tests-on-Windows.patch
  patch -p1 <"${srcdir}"/0003-RunGrepTest-compare-without-paying-attention-to-line.patch
  patch -p1 <"${srcdir}"/0004-RunGrepTest-skip-test-with-absolute-Unix-path.patch
  patch -p1 <"${srcdir}"/0005-RunGrepTest-skip-script-callout-test.patch
  patch -p1 <"${srcdir}"/0006-Fix-INTERACTIVE-fd-on-Windows.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-jit \
    --enable-pcre2-8 \
    --enable-pcre2-16 \
    --enable-pcre2-32 \
    --enable-pcre2grep-libz \
    --enable-pcre2grep-libbz2 \
    --enable-pcre2test-libedit

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  # License files
  cd "${pkgdir}${MINGW_PREFIX}/share"
  mkdir -p licenses/${_realname}
  mv doc/${_realname}/COPYING licenses/${_realname}
  mv doc/${_realname}/LICENCE licenses/${_realname}
}
